package cn.ad.server.persistence.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import cn.ad.server.domain.ad.AmountStore;

@Component
public interface AmountStoreDao {

	@Insert("insert into amount_store(cache_key, amount, object_id, object_type, amount_type,  create_time, update_time) values (#{cacheKey}, #{amount}, #{objectId}, #{objectType}, #{amountType}, now(), now())")
	public void save(AmountStore as);

	@Select("select * from amount_store where cache_key = #{value} limit 1")
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "cache_key", property = "cacheKey"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime") })
	public AmountStore findByKey(String key);

	@Update("update amount_store set amount = #{amount}, update_time = now() where id = #{id}")
	public void update(AmountStore as);

}
